Skip to content

Or module

Or

Bases: Module

Perform a logical Or operation.

It takes as input a list of data models, and returns a concatenation of them (if all are provided) otherwise it output the one that is not None.

If any input is None, it is ignored.

At build time the output has the schema of the first input, whatever happens at runtime: a schema with every field required (as structured output needs) cannot describe a result whose fields depend on which inputs are present. To collapse a Branch exactly, give its branches the same output schema.

Table:

x1 x2 Logical Or (|)
x1 x2 x1 + x2
x1 None x1
None x2 x2
None None None

Parameters:

Name Type Description Default
**kwargs keyword arguments

Standard keyword arguments for the module.

{}
Source code in synalinks/src/modules/merging/logical_or.py
@synalinks_export(
    [
        "synalinks.Or",
        "synalinks.modules.Or",
    ]
)
class Or(Module):
    """Perform a logical Or operation.

    It takes as input a list of data models,
    and returns a concatenation of them (if all are provided)
    otherwise it output the one that is not None.

    If any input is None, it is ignored.

    At build time the output has the schema of the first input, whatever
    happens at runtime: a schema with every field required (as structured
    output needs) cannot describe a result whose fields depend on which
    inputs are present. To collapse a `Branch` exactly, give its branches
    the same output schema.

    Table:

    | `x1`   | `x2`   | Logical Or (`|`) |
    | ------ | ------ | ---------------- |
    | `x1`   | `x2`   | `x1 + x2`        |
    | `x1`   | `None` | `x1`             |
    | `None` | `x2`   | `x2`             |
    | `None` | `None` | `None`           |

    Args:
        **kwargs (keyword arguments): Standard keyword arguments for the module.
    """

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    async def call(self, inputs, training=False):
        output = inputs[0]
        for i in range(1, len(inputs)):
            output = await ops.logical_or(
                output,
                inputs[i],
                name=f"module_or_{i}_" + self.name,
            )
        return output